<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加角色权限</title>
<link rel="stylesheet" type="text/css" href="../../css/style.css" />
<link rel="stylesheet" type="text/css" href="../../css/form.css" />
<link rel="stylesheet" href="../../css/ztreeStructure.css" type="text/css">
<link rel="stylesheet" href="../../css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" type="text/css" href="../../css/modelTree.css" />
<link rel="stylesheet" type="text/css" href="../../css/tree_Style.css" />
<link rel="stylesheet" type="text/css" href="../../css/layui.css" />
<style type="text/css">

	.node2{
		float: left;
	}
	.ul1{
		overflow: hidden;
	}
		.ztree li{
		width: max-content;
	    min-width: 170px;
	}
</style>
<!--[if IE 8]>
    <style type="text/css">
    #msg_mask{  
		            background: url(about:blank);
		        } 
        .mask {  
            background: url(about:blank);
        } 
        .loader {  
            background: url(about:blank);
        } 
    </style>
<![endif]-->
</head>
<body>
	<!-- 蓝色背景区域 -->
	<div class="wrap">
		<!-- 白色可用区域 -->
		<div class="canuse">
			<!------ 位置 ------>
			<p class="contentText local"><span>位置：系统管理 > 角色权限管理 > 添加角色权限</span></p>

			<div class="article_list" style="width: 98.5%; margin: 0px auto;">
				<!------- 内容 ------->
				<div class="content content1">
					<!-- 用户列表内容区 -->
					<div class="con con_01">
						<!-- 表单信息填写区 -->
						<h4 class="sel_title">
							<img src="../../img/list/brand1.png" /><span style="font-weight:bolder;">填写角色信息</span><span
								class="necessary">（带*号为必填项）</span>
						</h4>
						<div class="write_area" style="border-bottom: none;">
							<form method="post" id="addFrom">
								<table class="contentText" border="1" cellspacing="0"
									cellpadding="0" width="99%">

									<tr>
										<th>角色编码：</th>
										<td class="addRemind"><input id="groupCode" name="groupCode"
											 /> <span class="redColor">*</span></td>
										<th>角色名称：</th>
										<td class="addRemind"><input id="groupName" name="groupName"
											 /> <span class="redColor">*</span>
											 <input type="hidden" name="menuIds" id="menuIds" />
											 </td>
									</tr>
									<tr>
										<th>角色权限配置：
											<!-- 
												<div style="width:95%;"><img style="vertical-align:middle;" src="../../img/list/group_green.png">可读</div>
												<div style="width:95%;"><img style="vertical-align:middle;" src="../../img/list/group_red.png">读写</div>
											 -->
										</th>
										<td colspan="5" style="padding: 0;">
											<div id="treeDemo"  class="ztree" style="width: 1120px; height: 360px; overflow: auto; margin-left: 15px;">
											</div>
										</td>
									</tr>
									<tr>
										<th>备注：</th>
										<td colspan="5"><textarea id="userGroupDesc" name = "groupDesc"
												style="width: 95%; height: 80px"></textarea> <br></td>
									</tr>
								</table>
							</form>
							<!-- 保存、重置按钮区 -->
							<div align="center" class="btn_submit" style="margin-top: 20px;">
								<c:forEach items="${buttonList}" varStatus="status" var="item">
							<c:if test="${'USERGROUP_SAVE'==item}">
								<a onclick="submit()"
									class="bgd_blue_two img_hand contentText">确定</a> 
							</c:if>
							</c:forEach>
								<a href="usergroupList.html" class="bgd_white_two img_hand">
									返回 </a>
							</div>
							
						</div>
					</div>
				</div>
			</div>

		</div>
		<!-- 用户权限--可读--读写 -->
		<div class="mask hidden">
			<div class="input_radio" style="width: 400px;">
					<p>权限等级设置</p>
					<div id = "popWindow" style="width: 400px;">
					</div>
					<div><button onclick="sureRadio();" class="bgd_blue_two img_hand contentText">确定</button></div>
				</div>
		</div>
		<!-- 版尾  -->
		<div class="ending">Copyright 2019-2020 磐基技术有限公司</div>
	</div>
</body>
<script src='../../js/3rd/jquery-1.9.1.min.js' type='text/javascript' charset='utf-8'></script>
<script src="../../js/3rd/jquery.validate.min.js" type="text/javascript"></script>
<script src="../../js/common/common.js" type="text/javascript"></script>	
<script src="../../js/common/formSubmit.js" type="text/javascript"></script>
<script src="../../js/system/userGroupAdd.js" type="text/javascript"></script>
	
<script type="text/javascript" src="../../js/3rd/ztree/jquery-1.4.4.min.js"></script>
<script  src="../../js/3rd/ztree/jquery.ztree.core-3.5.js" type="text/javascript"></script>
<script  src="../../js/3rd/ztree/jquery.ztree.excheck-3.5.js" type="text/javascript"></script>
<script  src="../../js/3rd/ztree/jquery.ztree.exedit-3.5.js" type="text/javascript"></script>
<script type="text/javascript">

$(function(){
	
/*	$.ajax({
		url:"/userGroup/modelTree",
		type:"POST",
		data:{"content":"modelTree"},
		dataType:"json",
		success:function(resultData){
			  initTree("modelTree",resultData);
			 $.fn.zTree.init($("#treeDemo"), setting, resultData);
		},
		error:function(resultData){
			console.log("modelTree error!");
		}
	});*/
	var zNodes =[
		{ id:1, pId:-1, name:"系统管理", open:true},
		{ id:101, pId:1, name:"用户管理"},
		{ id:102, pId:1, name:"角色权限管理", },
		{ id:103, pId:1, name:"组织机构管理"},
		{ id:104, pId:1, name:"日志管理"},
		{ id:1011, pId:101, name:"用户增加", open:true, doCheck:false},
		{ id:1012, pId:101, name:"用户删除", doCheck:false},
		{ id:1012, pId:101, name:"密码重置", doCheck:false},
		{ id:1013, pId:101, name:"用户修改", checked:false, open:true, doCheck:false},
		{ id:1021, pId:102, name:"角色增加", doCheck:false},
		{ id:1022, pId:102, name:"角色删除", checked:false, doCheck:false},
		{ id:1023, pId:102, name:"角色修改", doCheck:false},
		{ id:1031, pId:103, name:"组织机构增加", open:true, doCheck:false},
		{ id:1032, pId:103, name:"组织机构修改", doCheck:false},
		{ id:1033, pId:103, name:"组织机构删除", doCheck:false},
		{ id:1041, pId:104, name:"日志查看", doCheck:false},
		{ id:2, pId:-1, name:"基础数据管理", open:true},
		{ id:201, pId:2, name:"产线管理"},
		{ id:202, pId:2, name:"工位管理"},
		{ id:203, pId:2, name:"产品信息管理",checked:false},
		{ id:204, pId:2, name:"零部件信息管理",checked:false},
		{ id:205, pId:2, name:"工艺管理"},
		{ id:206, pId:2, name:"通用工艺管理"},
		{ id:207, pId:2, name:"BOM信息管理",checked:false},
		{ id:208, pId:2, name:"工序工装量具管理",checked:false},
		{ id:2011, pId:201, name:"产线增加",checked:false, doCheck:false},
		{ id:2012, pId:201, name:"产线删除", doCheck:false},
		{ id:2013, pId:201, name:"产线修改", doCheck:false},
		{ id:2021, pId:202, name:"工位增加", doCheck:false},
		{ id:2022, pId:202, name:"工位删除", checked:false, doCheck:false},
		{ id:2023, pId:202, name:"工位修改", doCheck:false},
		{ id:2031, pId:203, name:"产品信息增加", doCheck:false},
		{ id:2032, pId:203, name:"产品信息修改", doCheck:false},
		{ id:2033, pId:203, name:"产品信息删除", doCheck:false},
			{ id:2041, pId:204, name:"零部件信息增加", open:true},
		{ id:2042, pId:204, name:"零部件信息修改"},
		{ id:2043, pId:204, name:"零部件信息删除", },
		{ id:2051, pId:205, name:"工艺增加"},
		{ id:2052, pId:205, name:"工艺删除"},
		{ id:2053, pId:205, name:"工艺修改", open:true, doCheck:false},
		{ id:2061, pId:206, name:"通用工艺增加", doCheck:false},
		{ id:2062, pId:206, name:"通用工艺修改", doCheck:false},
		{ id:2063, pId:206, name:"通用工艺删除", checked:false, open:true, doCheck:false},
		{ id:2071, pId:207, name:"BOM增加", doCheck:false},
		{ id:2072, pId:207, name:"BOM删除", checked:false, doCheck:false},
		{ id:2073, pId:207, name:"BOM修改", doCheck:false},
		{ id:2074, pId:207, name:"BOM导入"},
		{ id:2075, pId:207, name:"BOM模板"},
		{ id:2081, pId:208, name:"工序工装增加", open:true, doCheck:false},
		{ id:2082, pId:208, name:"工序工装修改", doCheck:false},
		{ id:2083, pId:208, name:"工序工装删除", doCheck:false},
		{ id:3, pId:-1, name:"基础信息管理", open:true},
		{ id:301, pId:3, name:"物资基本信息"},
		{ id:302, pId:3, name:"物资类型管理"},
		{ id:303, pId:3, name:"仓库管理",checked:false},
		{ id:304, pId:3, name:"库位管理",checked:false},
		{ id:3011, pId:301, name:"物资基本信息增加"},
		{ id:3012, pId:301, name:"物资基本信息删除"},
		{ id:3013, pId:301, name:"物资基本信息修改",checked:false},
		{ id:3014, pId:301, name:"物资基本信息导入",checked:false},
		{ id:3021, pId:302, name:"物资类型增加",checked:false, doCheck:false},
		{ id:3012, pId:302, name:"物资类型删除", doCheck:false},
		{ id:3013, pId:302, name:"物资类型修改", doCheck:false},
		{ id:3031, pId:303, name:"仓库增加", doCheck:false},
		{ id:3032, pId:303, name:"仓库删除", checked:false, doCheck:false},
		{ id:3033, pId:303, name:"仓库修改", doCheck:false},
		{ id:3041, pId:304, name:"库位增加", doCheck:false},
		{ id:3042, pId:304, name:"库位修改", doCheck:false},
		{ id:3043, pId:304, name:"库位删除", doCheck:false},
		{ id:4, pId:-1, name:"我的工作台", open:true},
		{ id:5, pId:-1, name:"库存日常管理", open:true},
		{ id:6, pId:-1, name:"库存盘点管理", open:true},
		{ id:7, pId:-1, name:"物资查询", open:true},
		{ id:8, pId:-1, name:"物资需求管理", open:true},
		{ id:9, pId:-1, name:"质量管理", open:true},
		{ id:10, pId:-1, name:"设备管理", open:true, doCheck:false},
		{ id:11, pId:-1, name:"生产工单管理", open:true, doCheck:false},
		{ id:12, pId:-1, name:"生产过程管理", open:true, doCheck:false},
		{ id:13, pId:-1, name:"生产数据统计", checked:false, open:true, doCheck:false},
		{ id:14, pId:-1, name:"产线状态统计", open:true, doCheck:false},
		{ id:401, pId:4, name:"我的待办事项", checked:false, doCheck:false},
		{ id:402, pId:4, name:"我的报警信息", doCheck:false},
		{ id:501, pId:5, name:"入库管理"},
		{ id:502, pId:5, name:"出库管理"},
		{ id:601, pId:6, name:"盘点规则管理", open:true, doCheck:false},
		{ id:602, pId:6, name:"盘点", doCheck:false},
		{ id:603, pId:6, name:"盘点审核", doCheck:false},
		{ id:604, pId:6, name:"盘点差异调整", open:true},
		{ id:701, pId:7, name:"物资库存查询"},
		{ id:702, pId:7, name:"物资预警查询"},
		{ id:801, pId:8, name:"物料需求管理", checked:false, doCheck:false},
		{ id:901, pId:9, name:"质量统计分析", doCheck:false},
		{ id:902, pId:9, name:"AOI检验数据分析"},
		{ id:903, pId:9, name:"SPI检验数据分析"},
		{ id:904, pId:9, name:"质量数据维护", open:true, doCheck:false},
		{ id:905, pId:9, name:"质量信息管理", doCheck:false},
		{ id:1011, pId:10, name:"设备基础信息管理", doCheck:false},
		{ id:1012, pId:10, name:"设备参数报警", open:true},
		{ id:1013, pId:10, name:"设备故障处理"},
		{ id:1014, pId:10, name:"设备状态统计分析"},
		{ id:1015, pId:10, name:"设备OEE分析"},
		
		{ id:1101, pId:11, name:"生产计划管理", checked:false, doCheck:false},
		{ id:1102, pId:11, name:"生产过程管理", doCheck:false},
		{ id:1201, pId:12, name:"生产开工报工"},
		{ id:1202, pId:12, name:"生产异常反馈"},
		{ id:1301, pId:13, name:"生产产能统计", open:true, doCheck:false},
		{ id:1302, pId:13, name:"人员班组统计", doCheck:false},
		{ id:1303, pId:13, name:"在制品管理", doCheck:false},
		{ id:1304, pId:13, name:"产品信息统计", open:true},
		{ id:1401, pId:14, name:"产线状态统计"},
		
	];
	 $.fn.zTree.init($("#treeDemo"), setting, zNodes);
	
});
	var h = document.documentElement.clientHeight;
	$(".wrap").css("height", h);

	// 获取每行 td 的兄弟节点
	$(".info_area td").hover(function() {
		$(this).parent().children().addClass("td_hover");
	}, function() {
		$(this).parent().children().removeClass("td_hover");
	});

	choseNow = null;
	// 出现读写权限设置
	$(".input_checkBox").change(function() {
		if (this.checked) {
			if (this.name[0] == "T") {
				$(".mask").css("display", "block");
				choseNow = this;
			}
		} else {
			if (!-[ 1, ]) {
				this.nextSibling.style.backgroundColor = 'white';
				this.nextSibling.style.color = 'black';
			} else {
				this.nextElementSibling.style.backgroundColor = 'white';
				this.nextElementSibling.style.color = 'black';
			}
		}
	});
	
	//权限分配Ztree
	var setting = {
		view: {
			selectedMulti: false
		},
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			beforeCheck: beforeCheck,
			onCheck: onCheck
		}
	};
	var code, log, className = "dark";
	function beforeCheck(treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		checkNodesByCK(treeNode,zTree);
		className = (className === "dark" ? "":"dark");
		showLog("[ "+getTime()+" beforeCheck ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
		return (treeNode.doCheck !== false);
	}
	
	//勾选节点时，将带有“查看”的节点都勾选上
	function checkNodesByCK(treeNode,zTree){
		var peerNodes = getPeerNodes(treeNode);
		if(peerNodes==null){
			return;
		}
		if(treeNode.name.search("查看")!=-1){
			for (var i = 0; i < peerNodes.length; i++) {
				if(peerNodes[i].name.search("查看")==-1){
					zTree.checkNode(peerNodes[i],false);
					var chilrenNodes = peerNodes[i].children;
					if(chilrenNodes!=null){
						for (var j = 0; j < chilrenNodes.length; j++) {
							zTree.checkNode(chilrenNodes[j],false);
						}
					}
				}
			}
		}else{
			for (var i = 0; i < peerNodes.length; i++) {
				if(treeNode!=peerNodes[i] && peerNodes[i].name.search("查看")!=-1){
					zTree.checkNode(peerNodes[i],true);
				}
			}
		}
		checkNodesByCK(getParentNode(treeNode),zTree);
	}
	
	function onCheck(e, treeId, treeNode) {
		showLog("[ "+getTime()+" onCheck ]&nbsp;&nbsp;&nbsp;&nbsp;" + treeNode.name );
	}		
	function showLog(str) {
		if (!log) log = $("#log");
		log.append("<li class='"+className+"'>"+str+"</li>");
		if(log.children("li").length > 6) {
			log.get(0).removeChild(log.children("li")[0]);
		}
	}
	//获取兄弟节点
	function getPeerNodes(treeNode){
		if(treeNode==null){
			return null;
		}else{
			if(treeNode.getParentNode()!=null){
				return treeNode.getParentNode().children;
			}
			return null;
		}
	}
	//获取父节点
	function getParentNode(treeNode){
		if(treeNode==null){
			return null;
		}else{
			return treeNode.getParentNode();
		}
	}
	function getTime() {
		var now= new Date(),
		h=now.getHours(),
		m=now.getMinutes(),
		s=now.getSeconds(),
		ms=now.getMilliseconds();
		return (h+":"+m+":"+s+ " " +ms);
	}

	function checkNode(e) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
		type = e.data.type,
		nodes = zTree.getSelectedNodes();
		if (type.indexOf("All")<0 && nodes.length == 0) {
			alert("请先选择一个节点");
		}

		if (type == "checkAllTrue") {
			zTree.checkAllNodes(true);
		} else if (type == "checkAllFalse") {
			zTree.checkAllNodes(false);
		} else {
			var callbackFlag = $("#callbackTrigger").attr("checked");
			for (var i=0, l=nodes.length; i<l; i++) {
				if (type == "checkTrue") {
					zTree.checkNode(nodes[i], true, false, callbackFlag);
				} else if (type == "checkFalse") {
					zTree.checkNode(nodes[i], false, false, callbackFlag);
				} else if (type == "toggle") {
					zTree.checkNode(nodes[i], null, false, callbackFlag);
				}else if (type == "checkTruePS") {
					zTree.checkNode(nodes[i], true, true, callbackFlag);
				} else if (type == "checkFalsePS") {
					zTree.checkNode(nodes[i], false, true, callbackFlag);
				} else if (type == "togglePS") {
					zTree.checkNode(nodes[i], null, true, callbackFlag);
				}
			}
		}
	}

	function setAutoTrigger(e) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.setting.check.autoCheckTrigger = $("#autoCallbackTrigger").attr("checked");
		$("#autoCheckTriggerValue").html(zTree.setting.check.autoCheckTrigger ? "true" : "false");
	}
</script>
<script type="text/javascript">
	$("input[name^='S']").attr("disabled", true);
	//给所有的二级选择框添加取消事件
	$("input[name^='S']").click(function(){
		//如果它取消选中，将子级选中框全部设置为未选中
		if(!this.checked){
			$.each($(this).parent().next().find("input"),function(index,element){
				element.checked=false;
				var lable = $(element).next();
				lable.css("backgroundColor","white");
				lable.css("color","black");
			});
			this.disabled = true;
		}else{
		}
	});
	//给所有的三级选择框添加二级选中联动事件
	$("input[name^='T']").click(function(){
		//如果它取消选中，判断他的兄弟inputs是否全部取消
		if(!this.checked){
			/* var checkedNum = 0;
			$.each($(this).parent().parent().find("input"),function(index,element){
				if(element.checked=true){
					checkedNum += 1;
				}
			});
			if(checkedNum == 0){
				$(this).parent().parent().parent().parent().prev().find("input").attr("checked",false);
			} */
		}else{
			//如果它选中，将他的父级input选中
			$(this).parent().parent().parent().parent().prev().find("input").prop("checked",true);
			$(this).parent().parent().parent().parent().prev().find("input").prop("disabled", false);
		}
	});
</script>
<script type="text/javascript">
	// 点击确定
	function submit(){
	  // 将树结构的id赋值到隐藏
		// 获取ztree勾选节点集合 
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var nodes = treeObj.getCheckedNodes(true);
		// 获取所有节点id 
		var array = new Array();
		for(var i=0 ; i< nodes.length ; i++){
			array.push(nodes[i].id);
		}
		var menuIds = null;
		if(array.length > 0){
			
			menuIds = array.join(",");
		}
		$("#menuIds").val( menuIds);
		
		// 调用
		userGroupAdd.submit();
	}
</script>
</html>
